#include "stdafx.h"
#include "DefaultObjectContactCallback.h"

DefaultObjectContactCallback::DefaultObjectContactCallback( irrklang::ISoundEngine* soundEngine  ) : OgreNewt::ContactCallback()
{
	sEngine=soundEngine;
}

DefaultObjectContactCallback::~DefaultObjectContactCallback(void)
{
}

int DefaultObjectContactCallback::onAABBOverlap( OgreNewt::Body* body0, OgreNewt::Body* body1, int threadIndex )
{
    if( body0->getType() == 3 || body1->getType() == 3 )
        return 1;

    return 0;
}

void DefaultObjectContactCallback::contactsProcess( OgreNewt::ContactJoint &contactJoint, Ogre::Real timeStep, int threadIndex )
{

	Ogre::Vector3 ppos,norm;
	contactJoint.getFirstContact().getPositionAndNormal(ppos,norm);



	if(abs(contactJoint.getFirstContact().getNormalSpeed())>11)
	{
			//Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(Ogre::StringConverter::toString(ppos),Ogre::LML_NORMAL);
		irrklang::ISound* music = sEngine->play3D("../../media/metalgrate4.wav",irrklang::vec3df(ppos.x,ppos.y,ppos.z), false, false, true, irrklang::ESM_AUTO_DETECT, false);
		music->setMaxDistance(10);
	}
	
}

